
@mixin input-base() {
  position: relative;
  width: 100%;
  color: var(--color-text);

  input,
  textarea {
    position: relative;
    width: 100%;
    padding: 0;
    background-color: transparent;
    background-image: none;
    border: 0;
    outline: 0;
    -webkit-appearance: none;
    color: var(--color-text);
    line-height: var(--input-line-height);

    @include placeholder {
      color: var(--color-text-placeholder);
    }
  }

  input {
    display: inline-block;
    height: var(--input-line-height);
  }

  textarea {
    display: block;
    resize: none;
    word-break: break-all;
    word-wrap: break-word;
    overflow: visible;
  }

  @include e(content) {
    position: relative;
    height: var(--input-line-height);
    line-height: var(--input-line-height);
  }
}

@mixin input-keyboard() {
  @include e(virtual-input) {
    display: flex;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
  }

  @include m(focus) {
    @include e(virtual-input) {
      display: flex;
      align-items: center;
      transform: translate3d(0, 0, 0);

      &:after {
        content: '';
        display: inline-block;
        height: var(--input-cursor-height);
        border-right: var(--input-cursor-width) solid var(--input-cursor-color);
        transition: opacity 0.1s ease-out;
        animation: virtual-cursor 1s infinite step-start;
      }
    }
  }

  @include m(readonly) {
    @include e(virtual-input) {
      position: static;
      white-space: normal;
    }
  }
}

@mixin input-placeholder() {
  @include placeholder {
    color: var(--color-text-placeholder);
  }

  @include e(placeholder) {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    color: var(--color-text-placeholder);
  }
}

@mixin input-clearable() {
  @include e(clear) {
    position: absolute;
    visibility: hidden;
    color: var(--input-clear-icon-color);
    width: var(--input-clear-icon-width);
    text-align: center;
    top: 50%;
    transform: translateY(-50%);
    right: 0;
    font-size: r(16);
  }

  @include m(focus) {
    padding-right: var(--input-clear-icon-width);

    @include e(clear) {
      visibility: visible;
    }
  }
}

@mixin input-disabled() {
  input,
  textarea {
    cursor: not-allowed;
    color: var(--color-text-disabled);
    // 用于修复真机上不显示的bug
    -webkit-text-fill-color: var(--color-text-disabled);
    opacity: 1;

    @include placeholder {
      color: var(--color-text-disabled);
    }
  }

  @include e(content, placeholder) {
    cursor: not-allowed;
    color: var(--color-text-disabled);
  }
}

@keyframes virtual-cursor {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}
